import typing
from typing import List
from provate import Stack

# 题目：定义栈的数据结构，在该类型中实现一个能够得到栈的最小元素的min函数，调用min,push,pop的时间复杂度都是O(1)

class stick_with_min(Stack):
    def __init__(self):
        Stack.__init__(self)
        self._min_list = []

    def push(self, val):
        self.list.append(val)

        if not self._min_list or val<=self._min_list[-1]:
            self._min_list.append(val)
        else:
            self._min_list.append(self._min_list[-1])

    def popout(self):
        if not self.list and not self._min_list:
            raise ValueError("the stack is empty")
        self._min_list.pop()
        return self.list.pop()

    def min(self):
        if not self.list and not self._min_list:
            raise ValueError("the stack is empty")

        return self._min_list[-1]

